const GET_CURRENT_USER_DOMAINS_URL = "organization/domain/list/currentUserIn";
const SWITCH_DOMAINS_URL = "organization/domain/switch/{domain}";
const GET_DOMIAN_ROOT_ORG_URL = "organization/domain/{domain}/root_org?expandMember={expandMember}&expandOrg={expandOrg}";
const GET_ALL_DOMAINS_URL = "organization/domain/list/all";
const GET_LOGIN_DOMAINS_BY_ACCOUNT_URL = "organization/domain/list/account/{account}/login";

const organizationDomain = {
    /**
     * 获取当前用户所在组织信息
     */
    async getCurrentUserDomains() {
      return request.get(GET_CURRENT_USER_DOMAINS_URL);
    },

    /**
     * 获取系统所有组织域信息
     */
     getAllDomains() {
      return request.get(GET_ALL_DOMAINS_URL);
    },

    /**
     * 获取传入账号所在组织域信息
     * @param account 账号
     */
    getLoginDomainsByAccount(account) {
      let url = GET_LOGIN_DOMAINS_BY_ACCOUNT_URL.replace("{account}", account);
      return request.get(url);
    },

    /**
     * 获取当前用户所在组织信息
     * @param domain
     */
    async switchDomain(domain) {
      let url = SWITCH_DOMAINS_URL.replace("{domain}", domain);
      return request.post(url);
    },

    async getDomainRootOrg({ domain, expandOrg, expandMember }) {
      let url = GET_DOMIAN_ROOT_ORG_URL.replace("{domain}", domain);
      if (expandOrg) {
        url = url.replace("{expandOrg}", true);
      } else {
        url = url.replace("{expandOrg}", false);
      }

      if (expandMember) {
        url = url.replace("{expandMember}", true);
      } else {
        url = url.replace("{expandMember}", false);
      }
      return request.post(url);
  },
};
export default organizationDomain;
